package cst.a706gdy.zyfypt_706gdy.Fragment;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;


import cst.a706gdy.zyfypt_706gdy.Adapter.twareAdapter;
import cst.a706gdy.zyfypt_706gdy.R;
import cst.a706gdy.zyfypt_706gdy.bean.twareBean;
import cst.a706gdy.zyfypt_706gdy.listener.AmicoolListener;
import cst.a706gdy.zyfypt_706gdy.model.ResModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class twareFragment extends Fragment {
    private RecyclerView recyclerView;
    private twareAdapter adapter;
    private List<twareBean> list;
    private RecyclerView.LayoutManager layoutManager;
    private AmicoolListener<List<twareBean>> listener;
    private ResModel model;
    private SharedPreferences sp;
    public twareFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_tware, container, false);
        recyclerView=(RecyclerView)view.findViewById(R.id.tware_rec);
        adapter =new twareAdapter(getActivity());
        list=new ArrayList<twareBean>();
        layoutManager=new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        listener=new AmicoolListener<List<twareBean>>() {
            @Override
            public void onResponse(List<twareBean> l) {
                adapter.setList(l);
            }

            @Override
            public void onFail(String msg) {

            }
        };
        sp=getActivity().getSharedPreferences("ME", Context.MODE_PRIVATE);
        model=new ResModel("gson",sp.getString("session_id",""));
        model.getList("tware",1,listener);
        return view;
    }

}
